<template>
  <view class="content">
    <!-- <image class="logo" src="/static/logo.png"></image>
    <view class="text-area">
      <text class="title">Hello 芋道</text>
    </view> -->
	<view class="swiper">
		<u-swiper
			height="187px"
			:list="list1"
			:indicator="true"
		></u-swiper>
	</view>
	<view class="applyfor">
		<view class="heads">
			<view class="dian"></view>
			<view class="names">发起流程</view>
		</view>
		<view class="gridBox">
			<u-grid
				col="4"
				:border="false"
				@click="clickGrid"
			>
				<u-grid-item
					:customStyle="{height:160+'rpx'}"
					v-for="(listItem,listIndex) in list"
					:key="listIndex"
				>
					<u-icon
						:customStyle="{paddingTop:20+'rpx'}"
						:name="listItem.name"
						:size="22"
					></u-icon>
					<text class="grid-text">{{listItem.title}}</text>
				</u-grid-item>
			</u-grid>
		</view>
	</view>
  </view>
</template>

<script>
	import { getAccessToken } from '@/utils/auth'
	export default {
		data(){
			return {
				list1: [
					'https://cdn.uviewui.com/uview/swiper/swiper1.png',
					'https://cdn.uviewui.com/uview/swiper/swiper2.png',
					'https://cdn.uviewui.com/uview/swiper/swiper3.png',
				],
				list: [
					{
						name: 'man-delete',
						type:'leave',
						title: '请假申请'
					},
					{
						name: 'man-delete',
						type:'absence',
						title: '销假申请'
					},
					{
						name: 'man-delete',
						type:'overtime',
						title: '加班申请'
					},
					{
						name: 'car-fill',
						type:'car',
						title: '用车申请'
					},
					{
						name: 'file-text-fill',
						type:'file',
						title: '文件传阅'
					},
					{
						name: 'gift-fill',
						type:'materials',
						title: '保障物资'
					},
					{
						name: 'gift-fill',
						type:'materials',
						title: '公示栏'
					},
					{
						name: 'gift-fill',
						type:'',
						title: '公文发送'
					}
				],
			}
		},
		methods:{
			isWorkWechat() {
			      //获取user-agaent标识头
			      var ua = window.navigator.userAgent.toLowerCase();
			      //判断ua和微信浏览器的标识头是否匹配
			      if ((ua.match(/micromessenger/i) == 'micromessenger') && (ua.match(/wxwork/i) == 'wxwork')) {
			            return true;
			      } else {
			            return false;
			      }
			},
			getWeChatCode() {
			  let local = encodeURIComponent(window.location.href); //获取当前页面地址作为回调地址
			  let appid = 'wxf5282b369937646a'
					
			  //通过微信官方接口获取code之后，会重新刷新设置的回调地址【redirect_uri】
			  window.location.href =
				"https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
				appid +
				"&redirect_uri=" +
				local +
				"&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect";
			},
			// 点击宫格
			clickGrid(index){
				console.log(index)
				if(index == 0){
					// 请假申请
					uni.navigateTo({
						url:'/pages/process/leave/create'
					})
				}else if(index == 1){
					// 消假申请
					uni.navigateTo({
						url:'/pages/process/leaveclear/create'
					})
				}else if(index == 2){
					// 消假申请
					uni.navigateTo({
						url:'/pages/process/overtime/create'
					})
				}else if(index == 3){
					// 用车申请
					uni.navigateTo({
						url:'/pages/process/useCar/create'
					})
				}else if(index == 4){
					// 消假申请
					uni.navigateTo({
						url:'/pages/process/doccirculate/create'
					})
				}else if(index == 5){
					// 应急保障
					uni.navigateTo({
						url:'/pages/process/inventory/create'
					})
				}else if(index == 6){
					// 应急保障
					uni.navigateTo({
						url:'/pages/process/column/create'
					})
				}
				// else if(index == 7){
				// 	// 公文发送
				// 	uni.navigateTo({
				// 		url:'/pages/process/column/create'
				// 	})
				// }
			}
		},
		onLoad(){
		},
		onShow(){
			// 判断是否登录
			if (!getAccessToken()) {
				// 未登录
				// 判断
				let isWeixin = this.isWorkWechat();
				console.log(isWeixin)
				if(isWeixin){
					// 微信授权登录
					// 跳转微信登录页面
					uni.reLaunch({
						url:'/pages/login/qywxLogin/qywxLogin'
					})
				}else{
					return false
					// 跳转手动登录页面
					this.$tab.reLaunch('/pages/login')
				}
			}else{
				// 已登录
			}
		}
	}
</script>

<style lang="less" scoped>
  .content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
	.swiper{
		width: 100%;
		height: auto;
	}
	.applyfor{
		width: 100%;
		height: auto;
		margin-top: 30rpx;
		.heads{
			width: 100%;
			height: 100rpx;
			display: flex;
			align-items: center;
			background-color: #fff;
			padding: 0 30rpx;
			box-sizing: border-box;
			border-bottom: 1px solid rgba(0,0,0,.1);
			.dian{
				width: 15rpx;
				height: 15rpx;
				background-color: #0081ff;
				border-radius: 50%;
			}
			.names{
				width: auto;
				font-size: 30rpx;
				color: #666;
				margin-left: 30rpx;
			}
		}
		.gridBox{
			width: 100%;
			height: auto;
			background-color: #fff;
			/deep/.u-grid-item{
				border-color: rgba(0,0,0,.1) !important;
			}
		}
	}
  }

  // .logo {
  //   height: 200rpx;
  //   width: 200rpx;
  //   margin-top: 200rpx;
  //   margin-left: auto;
  //   margin-right: auto;
  //   margin-bottom: 50rpx;
  // }

  // .text-area {
  //   display: flex;
  //   justify-content: center;
  // }

  // .title {
  //   font-size: 36rpx;
  //   color: #8f8f94;
  // }
</style>
